Car Model detection using YOLOv3 darknet

To access Google Drive Folder and Files

Original Version of Darknet

Modify Version of Darknet

Changing the variables to include OpenCV and GPU in the Makefile

How to train (to detect your custom objects):

Training Yolo v3:

1.Create file yolo-obj.cfg with the same content as in yolov3.cfg (or copy yolov3.cfg to yolo-obj.cfg) and:

So if classes=1 then should be filters=18. If classes=2 then write filters=21.

2.Create file obj.names in the directory build\darknet\x64\data\ with objects names - each in new line

3.Create file obj.data in the directory build\darknet\x64\data\ containing (where classes = number of objects):

4.Put image-files (.jpg) of your objects in the directory build/darknet/x64/data/obj/

1.1 Import necessary libraries

Repeat For Test

5.You should label each object on images from your dataset. Use this visual GUI-software for marking bounded boxes of objects and generating annotation files for Yolo v2 & v3:


LabelImg

LabelImg is a graphical image annotation tool.: https://github.com/tzutalin/labelImg


Yolo_mark

Windows & Linux GUI for marking bounded boxes of objects in images for training Yolo v3 and v2

https://github.com/AlexeyAB/Yolo_mark

It will create .txt-file for each .jpg-image-file - in the same directory and with the same name, but with .txt-extension, and put to file: object number and object coordinates on this image, for each object in new line: <object-class> <x> <y> <width> <height>

Where:

For example for img1.jpg you will be created img1.txt containing:

1 0.716797 0.395833 0.216406 0.147222
0 0.687109 0.379167 0.255469 0.158333
1 0.420312 0.395833 0.140625 0.166667

6.Create file train.txt and valid.txt in directory build\darknet\x64\data\ with filenames of your images, each filename in new line, with path relative to darknet, for example containing:

7.Download pre-trained weights for the convolutional layers (154 MB): https://pjreddie.com/media/files/darknet53.conv.74 and put to the directory build\darknet\x64

STOP

8.training by using the command line:

./darknet detector train build/darknet/x64/data/obj.data cfg/yolo-obj.cfg build/darknet/x64/darknet53.conv.74 -dont_show

8.1. For training with mAP (mean average precisions) calculation for each 4 Epochs (set valid=valid.txt or train.txt in obj.data file) and run:

./darknet detector train build/darknet/x64/data/obj.data cfg/yolo-obj.cfg build/darknet/x64/darknet53.conv.74 -dont_show -map

9.After training is complete - get result yolo-obj_final.weights from path build\darknet\x64\backup\

./darknet detector train data/obj.data yolo-obj.cfg yolo-obj_2000.weights

Custom object detection:

Example of Guns detection:

Image :

./darknet detector test build/darknet/x64/data/obj.data cfg/yolo-obj.cfg build/darknet/x64/guns_1000it.weights -thresh 0.20 data/ak47.jpg

Video :

./darknet detector demo build/darknet/x64/data/obj.data cfg/yolo-obj.cfg build/darknet/x64/guns_1000it.weights -thresh 0.20 -dont_show Guns.mp4 -out_filename Guns_output.mp4

Just Detection